import 'package:flutter/material.dart';
import 'package:xiecheng_lvyou/pages/home_page.dart';
import 'package:xiecheng_lvyou/pages/my_page.dart';
import 'package:xiecheng_lvyou/pages/search_page.dart';
import 'package:xiecheng_lvyou/pages/travel_page.dart';

class TabNavigator extends StatefulWidget {
  const TabNavigator({super.key});
  @override
  State<TabNavigator> createState() => _TabNavigatorState();
}

class _TabNavigatorState extends State<TabNavigator> {
  int _currentIndex = 0;
  PageController? _pageContorller;

  @override
  void initState() {
    super.initState();
    _pageContorller = PageController(initialPage: _currentIndex);
  }

  final List<Widget> _pageList = [
    const HomePage(),
    // hideLeft: widget.hideLeft,
    //             defaultText: widget.keyword,
    //             hint: widget.hint,
    const SearchPage(hideLeft: true, keyword: '', hint: '请输入关键词'),
    const TravelPage(),
    const MyPage(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        children: [
          PageView(
            physics: const NeverScrollableScrollPhysics(),
            controller: _pageContorller,
            children: _pageList,
          )
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: [
          _bottomItem('首页', Icons.home),
          _bottomItem('搜索', Icons.search),
          _bottomItem('旅拍', Icons.camera),
          _bottomItem('我的', Icons.account_circle),
        ],
        type: BottomNavigationBarType.fixed,
        fixedColor: Colors.red,
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
            _pageContorller?.jumpToPage(index);
          });
        },
      ),
    );
  }

  _bottomItem(String title, IconData icon) {
    return BottomNavigationBarItem(icon: Icon(icon), label: title);
  }
}
